<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="./js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="./js/angular.min.js"></script>
<style type="text/css">
.red{color:red;}
[ng-cloak]{display:none;}
[ng-cloak],.ng-cloak{display:none;}
</style>
</head>
<body>
<div ng-app="myApp" ng-controller="myAppController">
{{username}}
<p ng-repeat="x in userList">{{x.id}}----{{x.title}}----{{x.desc}}</p>
<hr>
{{usernameTwo}}
<p ng-repeat="xx in userListTwo">{{xx.id}}----{{xx.title}}----{{xx.desc}}</p>
</div>
<script type="text/javascript">
var url = "./PHP/1.get.php";
// 通过 provide 可以自定义服务
var myApp = angular.module("myApp",[],function($provide){	
	// service 服务
	$provide.service("customFour",function(){
		var name = "方法一";
		return {
			name : name,
			second : "方法二"
		};
	});
});
myApp.controller("myAppController",function($scope,$http,customFour){
	$scope.username = customFour.name;
	$scope.usernameTwo = customFour.second;
	$scope.userList = [
		{id:1,title:'标题11111',desc:'描述11111'},
		{id:2,title:'标题22222',desc:'描述22222'}
	];
	$scope.userList = null;
	$scope.userListssss = null;
	// 使用 $.get 来进行 get,利用 angular 的脏检查 来实现数据绑定
	$.get(url,{size:'5'},function(res){
		$scope.$apply(function(){
			$scope.userList = res;
			$scope.userListTwo = res;
		});
	},'json');
	// 使用angualr自带的 get 方法进行 get 请求
	// 多个请求考虑封装 angualr的get请求自带 脏检查
	ajaxGet(url,{size:'10'},function(res){ 
		$scope.userListTwo = res.data; 
	}); 
	function ajaxGet(url,data,fun){
	    $http.get(url,{params:data}).then(function(res){
	        fun(res);
	    });
	};
});
</script>
</body>
</html>